package com.frxuexi.lib_base.http

import android.content.Context
import androidx.room.Room
import com.frxuexi.lib_base.room.ParkDataBase
import com.frxuexi.lib_base.room.ShopDao
import com.frxuexi.lib_base.room.UserDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton


@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Singleton
    @Provides
    fun getApiService():ApiService=RetrofitUtil.retrofit.create(ApiService::class.java)

    @Singleton
    @Provides
    fun getShopApiService():ShopApiService=RetrofitUtil.shopRetrofit.create(ShopApiService::class.java)

    @Singleton
    @Provides
    fun initDB(@ApplicationContext context: Context):ParkDataBase{
        return Room.databaseBuilder(context,ParkDataBase::class.java,"park2302.db")
            .allowMainThreadQueries()
            .build()
    }

    @Singleton
    @Provides
    fun getUserDao(dataBase: ParkDataBase):UserDao{
        return dataBase.userDao()
    }

    @Singleton
    @Provides
    fun getShopDao(dataBase: ParkDataBase):ShopDao{
        return dataBase.shopDao()
    }
}